/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import java.awt.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.*;
import system.*;
import sql.*;

/**
 *
 * @author tj
 */
public class MyFrame extends JFrame {

    JPanel mainPanel;
    Container contentPane;
    MyMenuBar myMenuBar;
    LeftPanel leftPanel;
    RightPanel rightPanel;
    public LowerPanel lP;
    public UserHandler uH;
    public SQLHandler sql;
    

    public MyFrame(UserHandler uH, SQLHandler sql) {
        this.uH = uH;
        this.sql = sql;
        if (!sql.isConnected()) {
            sql.Connect();
        }
        MovieHandler movies = new MovieHandler(uH, sql);
        GradeHandler gh = new GradeHandler(sql,movies);
        addWindowListener(new WindowListenerCloser());
        mainPanel = new JPanel(new BorderLayout());
        contentPane = getContentPane();
        myMenuBar = new MyMenuBar(movies, uH.getCurrentUser().getUserName());

        rightPanel = new RightPanel(movies, this, uH, gh);
        leftPanel = new LeftPanel(movies, this, rightPanel, lP,gh,uH);

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        contentPane.setLayout(new BorderLayout());
        contentPane.add(mainPanel);
        mainPanel.add(leftPanel, BorderLayout.WEST);
        mainPanel.add(rightPanel, BorderLayout.CENTER);

        //pack(); // "Pack" the window, making it "just big enough".
        setVisible(true);


        setJMenuBar(myMenuBar);
        mainPanel.setBackground(Color.red);
        setTitle("Jmelt clean GUI experiment");
        setSize(920, 700);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setVisible(true);
        // setResizable(false);
    }

    public int getHeightOfFrameInColumns() {
        return (this.getHeight() / 16) - 10;
    }

    private class WindowListenerCloser implements WindowListener {

        public void windowOpened(WindowEvent e) {
        }

        public void windowClosing(WindowEvent e) {
            sql.endConnection();
        }

        public void windowClosed(WindowEvent e) {
        }

        public void windowIconified(WindowEvent e) {
        }

        public void windowDeiconified(WindowEvent e) {
        }

        public void windowActivated(WindowEvent e) {
        }

        public void windowDeactivated(WindowEvent e) {
        }
    }
}
